package com.itheima.service.impl;


import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.MemberDao;
import com.itheima.pojo.Member;
import com.itheima.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Service(interfaceClass = MemberService.class)
@Transactional
public class MemberServiceImpl implements MemberService {
    @Autowired
    private MemberDao memberDao;
    @Override
    public List<Integer> findAgeCount() {
        List<Member> member = memberDao.findAll();
        List<Integer> ageList = new ArrayList<>();
        Date date = new Date();
        int year1 = date.getYear();
        int age1 = 0,age2 = 0,age3 = 0,age4 = 0,age5 = 0,age6 = 0;
        for (Member member1 : member) {
            Date birthday = member1.getBirthday();
            int year = birthday.getYear();
            int count = year1-year;
            if (count<=6){
                age1++;
            }else if (count>7&&count<=12){
                age2++;
            }else if (count>12&&count<=17){
                age3++;
            }else if (count>18&&count<=45){
                age4++;
            }else if (count>46&&count<69){
                age5++;
            }else {
                age6++;
            }
        }
        ageList.add(age1);
        ageList.add(age2);
        ageList.add(age3);
        ageList.add(age4);
        ageList.add(age5);
        ageList.add(age6);
        return ageList;
    }
}
